package bo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.steam.splace.R;

import entity.Message;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class ListViewAdapter extends ArrayAdapter<Message>{
	 ArrayList<Message> array;
	 int resource;
	 TextView tvPlaceName;
	 TextView tvDescription;
	 Context context;
	 Message favorite;
	 View.OnTouchListener mTouchListener;
	public ListViewAdapter(Context context, 
			int textViewResourceId, ArrayList<Message> array, View.OnTouchListener listener) {
		super(context, textViewResourceId, array);
		this.context = context;
		 this.resource = textViewResourceId;
		 this.array = array;
		 mTouchListener = listener;
		// TODO Auto-generated constructor stub
	}
	 public View getView(int position, View convertView, ViewGroup parent){
		 
		 View friendView = convertView;
		 if(friendView ==null ){
		 friendView = new CustomListView(getContext());
		 friendView.setOnTouchListener(mTouchListener);
		 }
		 favorite = array.get(position);
		 if(favorite !=null){
			 tvPlaceName = ((CustomListView)friendView).tvPlaceName;
			 tvDescription = ((CustomListView)friendView).tvDescription;
		 // lay doi tuong friend va dua ra UI
		 tvPlaceName.setText(favorite.getPlaceName());
		 //Button Button1= (Button)  friendView.findViewById(R.id.btDeleteFavorite);

		 tvDescription.setText(favorite.getDescription());
		 
		 }
		 return friendView;
		 }
	 @Override
	 public Message getItem(int position) {
		 Message fav=null;
		 if(array.size()>0&&position<array.size())
			 fav=array.get(position);
	     return fav;
	 }
 /*  @Override
	    public long getItemId(int position) {
	        String item = getItem(position).getPlaceid()+"";
	        return mIdMap.get(item);
	    }*/
	    @Override
	    public boolean hasStableIds() {
	        return true;
	    } 
	 public void removeItemAt(int position){
		 
		 array.remove(position);
	 }
}
